package cn.fjsj.pubsub;

import cn.fjsj.constant.GlobalConstant;
import org.redisson.Redisson;
import org.redisson.api.RTopic;
import org.redisson.api.RedissonClient;
import org.redisson.config.Config;

public class Pub {
    public static void main(String[] args) {
        Config config = new Config();
        config.useSingleServer()
                        .setAddress(GlobalConstant.REDIS_ADDRESS);
        RedissonClient redissonClient = Redisson.create(config);
        RTopic topic = redissonClient.getTopic(GlobalConstant.TOPIC_NAME);
        // 发布
        long receivedClientCount = topic.publish(new Msg(1, "叼毛", "叼毛123"));        System.out.println("Hello, World!");
        System.out.println("一共 " + receivedClientCount + " 客户端收到了消息");
        redissonClient.shutdown();
    }
}